package com.fau.fm.entity;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;
import org.json.simple.JSONAware;
import org.json.simple.JSONObject;

/**
 * @desc 请假扣款实体类
 * @author liy
 * @datetime 2014年11月18日,上午10:19:38
 */
@Entity
@Table(name = "medical_leave_deduct")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class MedicalLeaveDeduct implements Serializable, JSONAware{

	private static final long serialVersionUID = 4577774406211280655L;
	
	private String id;
	private String leaveType;	// 请假类别
	
	@NotNull(message = "扣款金额不能为空！")
	private BigDecimal deduct;				// 扣款
	private Date createTime = new Date();	// 创建时间
	private Date updateTime = new Date();	// 更新时间
	
	private String leaveTypeName;			// 请假类别名称
	
	@Id
	@GenericGenerator(name = "generator", strategy = "uuid.hex")
	@GeneratedValue(generator = "generator")
	@Column(name = "id", length = 32)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	@Column(name = "leave_type", length = 20)
	public String getLeaveType() {
		return leaveType;
	}

	public void setLeaveType(String leaveType) {
		this.leaveType = leaveType;
	}

	@Column(name = "deduct", length = 9,precision = 2)
	public BigDecimal getDeduct() {
		return deduct;
	}

	public void setDeduct(BigDecimal deduct) {
		this.deduct = deduct;
	}
	
	@Column(name = "create_time")
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Column(name = "update_time")
	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	@Transient
	public String getLeaveTypeName() {
		return leaveTypeName;
	}

	public void setLeaveTypeName(String leaveTypeName) {
		this.leaveTypeName = leaveTypeName;
	}

	@SuppressWarnings("unchecked")
	@Override
	public String toJSONString() {
		JSONObject obj = new JSONObject();
		obj.put("id", id);
		obj.put("leaveType", leaveType);
		obj.put("leaveTypeName", leaveTypeName);
		obj.put("deduct", deduct);
		obj.put("createTime", DateFormatUtils.format(createTime,"yyyy-MM-dd HH:mm:ss"));
		obj.put("updateTime", DateFormatUtils.format(updateTime,"yyyy-MM-dd HH:mm:ss"));
		return obj.toString();
	}

}
